<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <title>查看销售统计</title>
    <link rel="stylesheet" href="../css/sign_in.css">
    <link rel="stylesheet" href="https://unpkg.com/element-ui/lib/theme-chalk/index.css">
</head>
<body>
<div id="app">
    <el-link type="primary" href="admin.html" target="_self">管理员进货</el-link>
    <el-link type="primary" href="admin2.html" target="_self">查看销售统计</el-link>
    <el-link type="primary" href="sign.html" target="_self">返回登录页面</el-link>

    <br><br>
    <el-button type="primary" round @click="sortByPrice">按月销售总额排序</el-button>
    <el-button type="primary" round @click="sortByNumber">按月销售总数排序</el-button>
    <br><br>
    <!--  表单数据: 订单信息 -->
    <template>
        <el-table
                :data="tableData"
                stripe
                style="width: 100%">
            <el-table-column
                    type="index"
                    label="排名"
                    :index="indexMethod">
            </el-table-column>
            <el-table-column
                    prop="month"
                    label="销售月份">
            </el-table-column>
            <el-table-column
                    prop="totalPrice"
                    label="月销售总额">
            </el-table-column>
            <el-table-column
                    prop="totalNumber"
                    label="月销售总数">
            </el-table-column>
        </el-table>
    </template>
</div>

<script src="../js/vue.js"></script>
<script src="https://unpkg.com/axios/dist/axios.min.js"></script>
<script src="https://unpkg.com/element-ui/lib/index.js"></script>
<script>
    //var userName = window.sessionStorage.getItem('userName');

    new Vue({
        el: "#app",
        mounted() {
            // var _this = this;
            axios({
                method: "get",
                url: "/totalPrice"
            }).then((res) => {
                this.tableData = res.data;
                console.log(this.tableData[0])
            })
        },
        data: {
            //var userName = window.sessionStorage.getItem('userName');
            tableData: [],
            dialogVisible: false,
        },
        methods: {
            sortByPrice() {
                axios({
                    method: "get",
                    url: "/totalPrice"
                }).then((res) => {
                    this.tableData = res.data;
                    console.log(this.tableData[0])
                })
            },
            sortByNumber() {
                axios({
                    method: "get",
                    url: "/totalNumber"
                }).then((res) => {
                    //this.tableData=null;
                    this.tableData = res.data;
                    console.log(this.tableData[0])
                })
            },
            indexMethod(index) {
                return index+1;
            }
        }
    })
</script>
</body>
</html>